<?php
$pageVars = Url::$pageVars[ 'GETPOST' ];
$method = $pageVars[ 'method' ];
$errorMsg = '';
$status = 0;
switch( $method ) {
	case 'getGroup' : {
		$groups = array();
		try{
			$teamId = isset( $pageVars[ 'id' ] ) ? $pageVars[ 'id' ] : 0;
			if( is_numeric( $teamId ) ){
				if( $teamId > 0 ){
					$groups = GroupUtility::getUserActiveGroupLists( $teamId );
					$groups[ 0 ] = array( 'text' => 'Select', 'id' => '' );
				}else{
					$groups[ 0 ] = array( 'text' => 'None', 'id' => '' );
				}
			}else{
				$groups[ 0 ] = array( 'text' => 'None', 'id' => '' );
			}
		}catch( Exception $ex ){
			$errorMsg = $ex->getMessage();
			$status = 1;
		}
		die( json_encode( array( 'groups' => $groups, 'status' => $status, 'msg' => $errorMsg ) ) );
	}case 'getGroupMember' : {
		$members = array();
		try{
			$groupId = isset( $pageVars[ 'id' ] ) ? $pageVars[ 'id' ] : 0;
			if( is_numeric( $groupId ) ){
				if( $groupId > 0 ){
					$members = GroupUtility::getActiveGroupMembers( $groupId );
					$members[ 0 ] = array( 'text' => 'Select', 'id' => '' );
				}else{
					$members[ 0 ] = array( 'text' => 'None', 'id' => '' );
				}
			}else{
				$members[ 0 ] = array( 'text' => 'None', 'id' => '' );
			}
		}catch( Exception $ex ){
			$errorMsg = $ex->getMessage();
			$status = 1;
		}
		die( json_encode( array( 'members' => $members, 'status' => $status, 'msg' => $errorMsg ) ) );
	}case 'getTeamMembers' : {
		$members = array();
		try{
			$teamId = isset( $pageVars[ 'id' ] ) ? $pageVars[ 'id' ] : 0;
			$members = array();
			if( is_numeric( $teamId ) ){
				if( $teamId > 0 ){
					$members = Utility::getTeamMembersLists( $teamId );
				}
			}
		}catch( Exception $ex ){
			$errorMsg = $ex->getMessage();
			$status = 1;
		}
		die( json_encode( array( 'members' => $members, 'status' => $status, 'msg' => $errorMsg ) ) );
	}
	default : exit;
}

